<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta charset="utf-8">
  <title>工序修改</title>
  <base href="<%=basePath%>">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" type="text/css" href="style/easyui/easyui.css">
</head>
<body>
  <div class="layui-form" lay-filter="layuiadmin-workorder-form-list" id="layuiadmin-workorder-form-list" style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" id="id" value="${workorder.workorder.id}"/>
    <input type="hidden" name="productworkorderid" id="productworkorderid" value="${workorder.productworkorderid}"/>
    <div class="layui-form-item layui-hide">
      <label class="layui-form-label" style="width: 20%">工序编号</label>
      <div class="layui-input-inline">
        <input type="text" name="ordercode" id="ordercode" lay-verify="required" placeholder="请输入工序编号" autocomplete="off" class="layui-input" value="${workorder.workorder.ordercode}">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 20%">工序名称</label>
      <div class="layui-input-inline">
        <input type="text" name="ordername" id="ordername" lay-verify="required" placeholder="请输入工序编号" autocomplete="off" class="layui-input" value="${workorder.workorder.ordername}">
      </div>
    </div>
    
    <div class="layui-upload">
        <label class="layui-form-label" style="width: 20%">视频文件:</label>
        <div class="layui-upload layui-input-block">


            <input type="hidden" id="filepath" name="filepath" value="${workorder.workorder.filepath }" />
            <button type="button" class="layui-btn layui-btn-primary" id="fileBtn"><i class="layui-icon">&#xe67c;</i>选择文件</button>
          <p class="layui-word-aux">请上传Avi格式的视频文件</p>

          <!--
            <button type="button" class="layui-btn layui-btn-warm" id="uploadBtn">开始上传</button>
             -->
        </div>

    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 20%">质检问题信息</label>
      <div class="layui-input-block">
        <!--下面的hidden用来提交复选框值用的，解决layui复选框提交到后台只有一个值的BUG-->
        <input type="hidden" name="problemcodes" id="problemcodes"/>
        <c:forEach  var="demo" items="${problemlist}" varStatus="status">
           <input type="checkbox" name="problemcode" lay-skin="primary" title="${demo.problemname}" value="${demo.problemcode}" <c:if test="${demo.pageSelected}">checked</c:if> <c:if test="${demo.pageUsed}">disabled</c:if>>
        </c:forEach>
      </div>
    </div>
    
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-workorder-form-submit" id="layuiadmin-workorder-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-workorder-form-edit" id="layuiadmin-workorder-form-edit" value="确认编辑">
    </div>
  </div>

  <script src="layuiadmin/layui/layui.js"></script>  
  <script src="layuiadmin/js/common/jquery.js"></script>
  <script src="layuiadmin/js/common/jquery.easyui.min.js"></script>
  <script src="layuiadmin/js/form.js"></script>
  <script>
 	layui.config({
	    base: 'layuiadmin/' //静态资源所在路径
	  }).extend({
	    index: 'lib/index' //主入口模块
	  }).use(['index', 'form', 'laydate','upload'], function(){
		  var $ = layui.$
		    ,admin = layui.admin
		    ,element = layui.element
		    ,layer = layui.layer
		    ,laydate = layui.laydate
		    ,upload = layui.upload
		    ,form = layui.form;
	    
		  upload.render({
                elem: '#fileBtn'
                ,url: 'workorder/saveFilepath'
                ,accept: 'file'
                 ,size: 20*1024    //20MB限制
                ,exts:'AVI|avi'
               ,auto: false
                 ,data: {
                	      id: function(){
                		    return $('#id').val();
                		  }
                		}
                ,choose: function(obj){  
                       //确认框
                       layer.confirm('确定导入文件吗？', {icon: 3, title:'提示'}, function(index){
                    	   layer.msg('正在提交请稍候。。。', {icon: 16,time:'-1',shade : [0.5 , '#000' , true]});
                            //读取本地文件
                           obj.preview(function(index, file, result){
                             //单个重传
                               obj.upload(index, file);
                           });
                               layer.close(index);
                         });
                 }
                
                 ,done: function(res){
                	 var code = res.code;
                     if(code && code==0){
                        //上传完毕回调
                         layer.msg("文件已经成功上传！");
                     }else{
                         var msg = res.msg;
                         layer.alert(msg);
                         return;
                     }
                 }
            });
		
	    //监听提交
	    form.on('submit(layuiadmin-workorder-form-submit)', function(obj){
	      	var field = obj.field; //获取提交的字段
	      	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
	
	      	//提交 Ajax 成功后，关闭当前弹层并重载表格
	      	//$.ajax({});
	      
	      	var chk_value =[];
	        $('input[name="problemcode"]:checked').each(function(){ 
	        	chk_value.push($(this).val()); 
	        });


          if(chk_value.length<=0){
            layer.msg("请选择至少一项检验问题到工序内");
            return false;
          }
          if(chk_value.length>7){
            layer.msg("检验问题最大数量为7个");
            return false;
          }



	        if(chk_value.length > 0){
	        	field.problemcodes = chk_value.join(',');//将数组合并成字符串

		      	layer.confirm('确定操作?', function(index){
		      		layer.msg('正在提交请稍候。。。', {icon: 16,time:'-1',shade : [0.5 , '#000' , true]});
		      		admin.req({
		    		    url: 'workorder/update' //实际使用请改成服务端真实接口
		    	        ,data: field
		    	        ,type: 'POST'
		    	        ,done: function(res){
		    	        	layer.msg(res.msg);
		    	        }
		         	});
		        });
	        }else{
	        	layer.msg("请先选择关联的工序信息");
	        	return false;
	        }
	        //parent.layui.table.reload('LAY-workorder-content-list'); //重载表格
	        //parent.layer.close(index); //再执行关闭 
	    });
	  })
  </script>
</body>
</html>